package com.codeavatar.hardwaretester.core;

import com.codeavatar.catools.ica.ICaConfig;
import com.codeavatar.catools.lib.sign.CaSignType;
import com.codeavatar.catools.helper.CaLogHelper;

/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2022
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
public class HTConfig implements ICaConfig {

    //++++++++++++++++++++++++++++++++++++++
    //++ 应用总控
    //++++++++++++++++++++++++++++++++++++++

    //应用发布开关
    private final boolean RELEASE_APP = false;
    //调试日志输出开关
    private final boolean OPEN_LOG = !RELEASE_APP;
    //系统日志输出开关
    private final boolean OPEN_SYSTEM_LOG = !RELEASE_APP;
    //API正式与测试切换开关
    private final boolean OPEN_NORMAL_API = RELEASE_APP;

    //++++++++++++++++++++++++++++++++++++++
    //++ IConfig 的抽象方法
    //++++++++++++++++++++++++++++++++++++++

    @Override
    public boolean isOpenLog() {
        return OPEN_LOG;
    }

    @Override
    public boolean isOpenSysLog() {
        return OPEN_SYSTEM_LOG;
    }

    @Override
    public String getApiRoot() {
        if (OPEN_NORMAL_API) {
            CaLogHelper.info("************【线上】API数据调用************");
            return HTConstVal.API_NORMAL;
        }
        CaLogHelper.info("############【线下】API数据调用############");
        return HTConstVal.API_TEST;
    }

    @Override
    public String getDomainRoot() {
        if (OPEN_NORMAL_API) {
            CaLogHelper.info("************【线上】站点调用************");
            return HTConstVal.DOMAIN_NORMAL;
        }
        CaLogHelper.info("############【线下】站点调用############");
        return HTConstVal.DOMAIN_TEST;
    }

    @Override
    public CaSignType getSignType() {
        return HTConstVal.SIGN_KEY_TYPE;
    }

    @Override
    public String getSignKey() {
        StringBuffer sb = new StringBuffer("");
        switch (HTConstVal.SIGN_KEY_TYPE){
            case Md5:
                sb.append(HTConstVal.SIGN_KEY_MD5);
            break;
            case Rsa:
                sb.append(HTConstVal.SIGN_KEY_RSA);
                break;
            case Rsa2:
                sb.append(HTConstVal.SIGN_KEY_RSA2);
                break;
            default:
                sb.append(HTConstVal.SIGN_CERT_PATH);
                break;
        }
        return sb.toString();
    }

    @Override
    public String getWebSocketHost() {
        if (OPEN_NORMAL_API) {
            CaLogHelper.info("************【线上】SOCKET数据调用************");
            return HTConstVal.WEBSOCKET_HOST_NORMAL;
        }
        CaLogHelper.info("############【线下】SOCKET数据调用############");
        return HTConstVal.WEBSOCKET_HOST_TEST;
    }

    @Override
    public int getWebSocketPort() {
        if (OPEN_NORMAL_API) {
            CaLogHelper.info("************【线上】SOCKET端口调用************");
            return HTConstVal.WEBSOCKET_PORT_NORMAL;
        }
        CaLogHelper.info("############【线下】SOCKET端口调用############");
        return HTConstVal.WEBSOCKET_PORT_TEST;
    }

    @Override
    public String getWechatAppId() {
        return HTConstVal.WECHAT_APPID;
    }

    @Override
    public String getWechatAppSecret() {
        return HTConstVal.WECHAT_APPSECRET;
    }
}
